<?php

function litimgurls( $imgid = 0 ) {
  global $lit_imglist, $dsql;
  //获取附加表
  $row = $dsql->GetOne( "SELECT c.addtable FROM #@__archives AS a LEFT JOIN #@__channeltype AS c 
                                                            ON a.channel=c.id where a.id='$imgid'" );
  $addtable = trim( $row[ 'addtable' ] );

  //获取图片附加表imgurls字段内容进行处理
  $row = $dsql->GetOne( "Select imgurls From `$addtable` where aid='$imgid'" );

  //调用inc_channel_unit.php中ChannelUnit类
  $ChannelUnit = new ChannelUnit( 2, $imgid );

  //调用ChannelUnit类中GetlitImgLinks方法处理缩略图
  $lit_imglist = $ChannelUnit->GetlitImgLinks( $row[ 'imgurls' ] );

  //返回结果
  return $lit_imglist;
}


/*
TAG标签调用示例：

1、如果你的模板里，还有TAG需要指向到它的静态地址，则用参考这个函数去处理其标签即可：
{dede:tag type='current'}
[field:id function='mbp_tag_url(@me)'/] 
{/dede:tag} 
其中的id就是这个TAG的ID号,获取的是TAG的url链接
  
2、在内容页模板，如果想指向该文TAG的列表页，用以下标签即可：
{dede:field.id function='mbp_arc_tag_link(@me)'/}

3、在文章列表页、arclist标签等，使用一下代码调用文章TAG列表
[field:id function='mbp_arc_tag_link(@me)'/]

*/

//重要的事说9遍  
//以下内容需要复制到：DEDECMS系统目录/include/extend.func.php 里面，注意不要覆盖了
//以下内容需要复制到：DEDECMS系统目录/include/extend.func.php 里面，注意不要覆盖了


//获取TAG静态地址
function mbp_tag_url( $tid ) {
  global $dsql;
  $sql = "select * from `#@__tagindex`  where id='$tid' ";
  $str = '';
  if ( $arcRow = $dsql->GetOne( $sql ) ) {
    $arcRow[ 'tagdir' ] = trim( $arcRow[ 'tagdir' ] );
    $arcRow[ 'id' ] = intval( $arcRow[ 'id' ] );
    $tag_basedir = trim( $GLOBALS[ 'cfg_tag_basedir' ], '/ ' );
    $tag_basedir = empty( $tag_basedir ) ? 'tag' : $tag_basedir;
    $tag_style = isset( $GLOBALS[ 'cfg_tag_style' ] ) ? intval( $GLOBALS[ 'cfg_tag_style' ] ) : 1;
    if ( $tag_style < 1 || $tag_style > 4 )$tag_style = 1;

    //1:拼音目录    
    if ( $tag_style == 1 ) {
      $str = $GLOBALS[ 'cfg_cmspath' ] . '/' . $tag_basedir . '/' . $arcRow[ 'tagdir' ] . '/';
    }

    //2:ID目录    
    if ( $tag_style == 2 ) {
      $str = $GLOBALS[ 'cfg_cmspath' ] . '/' . $tag_basedir . '/' . $arcRow[ 'id' ] . '/';
    }

    //3:拼音url   如：tag/baicai.html(白菜)   tag/baicai3.html(百菜)   
    if ( $tag_style == 3 ) {
      if ( $arcRow[ 'tagdir' ] == 'index' )$arcRow[ 'tagdir' ] .= $arcRow[ 'id' ];
      $str = $GLOBALS[ 'cfg_cmspath' ] . '/' . $tag_basedir . '/' . $arcRow[ 'tagdir' ] . '_1.html';
    }

    //4:ID url   如：tag/1.html   
    if ( $tag_style == 4 ) {
      $str = $GLOBALS[ 'cfg_cmspath' ] . '/' . $tag_basedir . '/' . $arcRow[ 'id' ] . '_1.html';
    }
  } else $str = "ID为$tid的TAG已被删除！";

  return $str;
}


//获取指定文章的TAG到相关TAG列表页的地址
// $html=<a href="{url}">{tag}</a>   自动替换为  $html=<a href="/tag/ceshi/">测试</a>
function mbp_arc_tag_link( $aid, $html = '' ) {
  global $dsql;
  $sql = "select tid from `#@__taglist`  where aid='$aid' group by tid ";
  $dsql->Execute( 'ala', $sql );
  while ( $row = $dsql->GetObject( 'ala' ) ) {
    $url = mbp_tag_url( $row->tid );
    if ( $arcRow = $dsql->GetOne( "select * from `#@__tagindex`  where id='" . $row->tid . "' " ) )$tag = $arcRow[ "tag" ];
    else $tag = "";
    //$str .= "<a href='{$url}' target='_blank'>{$tag}</a>"
    $html = trim( $html );
    if ( empty( $html ) ) {
      $str .= " <a href='" . $url . "' target=_blank>" . $tag . "</a> "; //在这里修改链接样式：$url 为链接   $tag为标签名称
    } else {
      $html = str_replace( '{url}', $url, $html );
      $html = str_replace( '{tag}', $url, $html );
      $str .= $html;
    }
  }
  return $str;
}

/*dede筛选自定义函数 开始*/
/**
 *  字符过滤函数(用于安全)
 *
 * @access    public
 * @param     string  $str  字符
 * @param     string  $stype  类型
 * @return    string
 */
function string_filter( $str, $stype = "inject" ) {
  if ( $stype == "inject" ) {
    $str = str_replace(
      array( "select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./" ),
      array( "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ),
      $str );

  } else if ( $stype == "xss" ) {
    $farr = array( "/\s+/",
      "/<(\/?)(script|META|STYLE|HTML|HEAD|BODY|STYLE |i?frame|b|strong|style|html|img|P|o:p|iframe|u|em|strike|BR|div|a|TABLE|TBODY|object|tr|td|st1:chsdate|FONT|span|MARQUEE|body|title|\r\n|link|meta|\?|\%)([^>]*?)>/isU",
      "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
    );
    $tarr = array( " ",
      "",
      "\\1\\2",
    );
    $str = preg_replace( $farr, $tarr, $str );
    $str = str_replace(
      array( "<", ">", "'", "\"", ";", "/*", "*", "../", "./" ),
      array( "&lt;", "&gt;", "", "", "", "", "", "", "" ),
      $str );
  }
  return $str;
}

/**
 * 筛选字段输出(用于发布)
 * 模板调用:{dede:php}AddFilter(17,1,"lyts");{/dede:php}
 * @access    public
 * @param     string  $channelid	模型id号
 * @param     string  $type		  	输出类型
 * @param     string  $fieldsnamef	字段名称
 * @param     string  $defaulttid	指定栏目id
 * @return    string
 */

function AddFilter( $channelid, $type = 1, $fieldsnamef = array(), $defaulttid = 0, $loadtype = 'autofield' ) {
  global $dsql, $tid, $id, $cfg_cmspath, $cfg_rewritea;
  $tid = $defaulttid ? $defaulttid : $tid;
  if ( $id != "" ) {
    $tidsq = $dsql->GetOne( " Select typeid From `#@__archives` where id='$id' " );
    $tid = $tidsq[ "typeid" ];
  }
  $plist = $_SERVER[ 'HTTP_X_REWRITE_URL' ] ? string_filter( $_SERVER[ 'HTTP_X_REWRITE_URL' ] ) : string_filter( $_SERVER[ 'REQUEST_URI' ] );
  if ( $cfg_rewritea == 'Y' ) {
    $typedirsq = $dsql->GetOne( " Select typedir From `#@__arctype` where id='$tid' " );
    $typedir = $typedirsq[ "typedir" ];
    $typedir = preg_replace( '/{cmspath}/', '', $typedir );
    $plist = stripos( $plist, "makehtml_list_action.php" ) ? $cfg_cmspath . $typedir . '/': $plist;
    $filterarr = string_filter( stripos( $plist, ".html" ) ? str_replace( ".html", "", $plist ) : $cfg_cmspath . $typedir . '/' );
  } else {
    $nofilter = ( isset( $_REQUEST[ 'TotalResult' ] ) ? "&TotalResult=" . $_REQUEST[ 'TotalResult' ] : '' ) . ( isset( $_REQUEST[ 'PageNo' ] ) ? "&PageNo=" . $_REQUEST[ 'PageNo' ] : '' );
    $filterarr = string_filter( stripos( $plist, "list.php?tid=" ) ? str_replace( $nofilter, '', $plist ) : $GLOBALS[ 'cfg_cmsurl' ] . "/plus/list.php?tid=" . $tid );
  }
  $cInfos = $dsql->GetOne( " Select * From  `#@__channeltype` where id='$channelid' " );
  $fieldset = $cInfos[ 'fieldset' ];
  $dtp = new DedeTagParse();
  $dtp->SetNameSpace( 'field', '<', '>' );
  $dtp->LoadSource( $fieldset );
  $dede_addonfields = '';
  if ( is_array( $dtp->CTags ) ) {
    $all_item = array();
    foreach ( $dtp->CTags as $tida => $ctag ) {
      $field_name = $ctag->GetName();
      $fieldsname = $fieldsnamef ? explode( ",", $fieldsnamef ) : explode( ",", $field_name );
      if ( ( $loadtype != 'autofield' || ( $loadtype == 'autofield' && $ctag->GetAtt( 'autofield' ) == 1 ) ) && in_array( $field_name, $fieldsname ) ) {
        $all_item[] = $field_name;
      }
    }
    foreach ( $dtp->CTags as $tida => $ctag ) {
      $field_name = $ctag->GetName();
      $fieldsname = $fieldsnamef ? explode( ",", $fieldsnamef ) : explode( ",", $field_name );
      if ( ( $loadtype != 'autofield' || ( $loadtype == 'autofield' && $ctag->GetAtt( 'autofield' ) == 1 ) ) && in_array( $field_name, $fieldsname ) ) {
        //$dede_addonfields .= '<b>' . $ctag->GetAtt( 'itemname' ) . '：</b>';
        if ( $cfg_rewritea == 'Y' ) {
          $filterparms = getFilterParms( $tid );
          $new_filter = array();
          foreach ( $filterparms as $key => $value ) {
            $new_filter[] = $key;
          }
          $name_key = array_search( $field_name, $new_filter );
          preg_match( '#[a-z]+?_\d+?_([a-z0-9_]+)#i', $filterarr, $href0 );
          $href0 = $href0 ? $href0[ 1 ] : "";
          $href1 = explode( "_" . $field_name . '_', "_" . $href0 );
          $href2 = ( $href1[ 1 ] != "" && strpos( $href1[ 1 ], "_" ) ) ? explode( '_', $href1[ 1 ] ) : array( $href1[ 1 ] != "" ? $href1[ 1 ] : "" );
          $fields_value = $href2 != array() ? $href2[ 0 ] : "";
          $fields_value1 = $fields_value != "" ? explode( '_', $fields_value ) : "";
          $all_href = str_replace( array( "_" . $field_name . "_" . $fields_value, "_" . $field_name . ".", "." ), array( "", ".", "." ), $filterarr . '.html' );
          if ( !preg_match( '/_[A-Za-z]+_\d+/i', $all_href ) ) {
            $all_href = $cfg_cmspath . $typedir . '/';
          }
          $dede_addonfields .= ( preg_match( "/_" . $field_name . "_/is", $filterarr, $regm ) ? '<a href="' . $all_href . '">全部</a>' : '<a class="on">全部</a>' );
          $href = "";
          $addonfields_items = explode( ",", $ctag->GetAtt( 'default' ) );
          for ( $i = 0; $i < count( $addonfields_items ); $i++ ) {
            $is_select = in_array( $i, $fields_value1 ) ? 1 : 0;
            $newarr = array();
            if ( stripos( $filterarr, "_" . $field_name . '_' ) ) {
              $valuestr = "";
              $newarr[] = $i;
              sort( $newarr );
              foreach ( $newarr as $value ) {
                $valuestr = "_" . $value;
              }
              $restr = $field_name . $valuestr;
              $href = str_replace( "_" . $field_name . "_" . $fields_value, "_" . $field_name . $valuestr, $filterarr );
              if ( !empty( $_REQUEST[ 'PageNo' ] ) ) {
                $href = preg_replace( "/_\d$/", "", $href );
              }
            } else {
              if ( $href0 ) {
                preg_match_all( '/[a-z]+_\d+/i', $href0, $href0_arr );
                $fstrarr = array();
                $fstr = "";
                foreach ( $all_item as $key => $value ) {
                  if ( $ctag->GetName() == $value ) {
                    $fstrarr[ $value ] = $value . "_" . $i;
                  }
                }
                $fstrarr = array_merge( $href0_arr[ 0 ], $fstrarr );
                sort( $fstrarr );
                foreach ( $fstrarr as $v ) {
                  $fstr .= "_" . $v;
                }
                $filterarr1 = explode( "list_", $filterarr );
                $href = $filterarr1[ 0 ] . "list_" . $tid . $fstr;
              } else {
                $filterarr1 = explode( "list_", $filterarr );
                $href = $filterarr1[ 0 ] . "list_" . $tid . '_' . $field_name . '_' . $i;
              }
            }
            $href .= ".html";
            $href = str_replace( array( "_" . $field_name . ".", ".", "_" . $_REQUEST[ 'TotalResult' ] . "_" . $_REQUEST[ 'PageNo' ] ), array( ".", ".", "" ), $href );

            $dede_addonfields .= ( ( ( strpos( $filterarr, $field_name . "_" . $fields_value ) == "" || $fields_value != $i ) && $is_select == 0 ) ? '<a href="' . $href . '">' . $addonfields_items[ $i ] . '</a>' : '<a class="on">' . $addonfields_items[ $i ] . '</a>' );
          }
        } else {
          $href1 = explode( $ctag->GetName() . '=', $filterarr );
          $href2 = explode( '&', $href1[ 1 ] );
          $fields_value = $href2[ 0 ];
          $fields_value1 = explode( "|", $fields_value );
          $dede_addonfields .= ( preg_match( "/&" . $ctag->GetName() . "=/is", $filterarr, $regm ) ? '<a title="全部" href="' . str_replace( "&" . $ctag->GetName() . "=" . $fields_value, "", $filterarr ) . '">全部</a>' : '<a class="on">全部</a>' );
          $addonfields_items = explode( ",", $ctag->GetAtt( 'default' ) );
          for ( $i = 0; $i < count( $addonfields_items ); $i++ ) {
            $href = stripos( $filterarr, $ctag->GetName() . '=' ) ? str_replace( "=" . $fields_value, "=" . urlencode( $addonfields_items[ $i ] ), $filterarr ) : $filterarr . '&' . $ctag->GetName() . '=' . urlencode( $addonfields_items[ $i ] );
            $href = str_replace( "&TotalResult=" . $_REQUEST[ 'TotalResult' ] . "&PageNo=" . $_REQUEST[ 'PageNo' ], "", $href );

            $dede_addonfields .= ( $fields_value != urlencode( $addonfields_items[ $i ] ) && $is_select != 1 ? '<a title="' . $addonfields_items[ $i ] . '" href="' . $href . '">' . $addonfields_items[ $i ] . '</a>' : '<a class="on">' . $addonfields_items[ $i ] . '</a>' );
          }
        }
      }
    }
  }
  echo $dede_addonfields;
}

function getFilterParms( $ptid, $part = 0 ) {
  global $dsql, $tid, $use_fields_name;
  $tid = $ptid ? $ptid : $tid;
  $tidsq = $dsql->GetOne( " Select channeltype,templist From `#@__arctype` where id='$tid' " );
  $channelid = $tidsq[ "channeltype" ];

  $cInfos = $dsql->GetOne( " Select * From  `#@__channeltype` where id='$channelid' " );
  $fieldset = $cInfos[ 'fieldset' ];
  $dtp = new DedeTagParse();
  $dtp->SetNameSpace( 'field', '<', '>' );
  $dtp->LoadSource( $fieldset );
  $ctag1 = $dtp->CTags;

  if ( $part == 1 ) {
    $tmpdir = $GLOBALS[ 'cfg_basedir' ] . $GLOBALS[ 'cfg_templets_dir' ];
    $tempfile = str_replace( array( "{tid}", "{cid}", "{style}" ), array( $tid, $cInfos[ 'nid' ], $GLOBALS[ 'cfg_df_style' ] ), $tidsq[ 'templist' ] );
    $tempfile = $tmpdir . "/" . $tempfile;
    if ( !file_exists( $tempfile ) ) {
      $tempfile = $tmpdir . "/" . $GLOBALS[ 'cfg_df_style' ] . "/list_default.htm";
    }
    $dtp1 = new DedeTagParse();
    $dtp1->LoadTemplate( $tempfile );
    $TempSource = $dtp1->SourceString;
    preg_match_all( "/{dede:php}(.*?){\/dede:php}/is", $TempSource, $regm );
    $use_fields_name = array();
    if ( $regm[ 0 ] ) {
      foreach ( $regm[ 0 ] as $key => $value ) {
        if ( strpos( $value, "AddFilter" ) > -1 ) {
          $attr = explode( "'", $value );
          $attr = explode( ",", $attr[ 1 ] );
        }
        $use_fields_name = array_merge( $use_fields_name, $attr );
      }
    }
  } else {
    $use_fields_name = $use_fields_name ? explode( ",", $use_fields_name ) : "";
  }
  if ( is_array( $ctag1 ) ) {
    $all_item = array();
    foreach ( $ctag1 as $tida => $ctag ) {
      $field_name = $ctag->GetName();
      $fieldsname = explode( ",", $field_name );
      if ( $ctag->GetAtt( 'autofield' ) == 1 && in_array( $field_name, $fieldsname ) ) {
        if ( $use_fields_name != "" && $part == 1 ) {
          if ( in_array( $field_name, $use_fields_name ) && $ctag->GetAtt( 'default' ) ) {
            $all_item[ $field_name ] = explode( ",", $ctag->GetAtt( 'default' ) );
          }
        } else {
          if ( $ctag->GetAtt( 'default' ) ) {
            $all_item[ $field_name ] = explode( ",", $ctag->GetAtt( 'default' ) );
          }
        }
      }
    }
  }
  return $all_item;
}
/**
 * 内容页输出所属筛选值+链接
 * 模板调用：{dede:field.id function=GetFilterUrl(@me,'bj')/}
 * @access    public
 * @param     string  $id文档id
 * @param     string  $fieldsnamef单个筛选字段
 * @return    string
 */
function GetFilterUrl( $id, $fieldsnamef ) {
  global $dsql, $cfg_cmspath, $cfg_rewritea;
  if ( !isset( $id ) && !is_numeric( $id ) ) {
    return '';
  } else {
    $arcrow = $dsql->GetOne( " Select typeid,channel From `#@__archives` where id='$id' " );
    $channelid = $arcrow[ 'channel' ];
    $tid = $arcrow[ 'typeid' ];
    $typerow = $dsql->GetOne( " Select typedir From `#@__arctype` where id='$tid' " );
    $typedir = MfTypedir( $typerow[ "typedir" ] );
    $channelrow = $dsql->GetOne( "SELECT addtable FROM #@__channeltype where id='$channelid'" );
    $addtable = trim( $channelrow[ 'addtable' ] );
    $fieldrow = $dsql->GetOne( "SELECT $fieldsnamef FROM `$addtable` WHERE aid=$id" );
  }
  $plist = $_SERVER[ 'HTTP_X_REWRITE_URL' ] ? string_filter( $_SERVER[ 'HTTP_X_REWRITE_URL' ] ) : string_filter( $_SERVER[ 'REQUEST_URI' ] );
  if ( $cfg_rewritea == 'Y' ) {
    $plist = stripos( $plist, "makehtml_list_action.php" ) ? $cfg_cmspath . $typedir . '/': $plist; //by巅峰
    $filterarr = string_filter( stripos( $plist, ".html" ) ? str_replace( ".html", "", $plist ) : $cfg_cmspath . $typedir . '/' );
  } else {
    $nofilter = ( isset( $_REQUEST[ 'TotalResult' ] ) ? "&TotalResult=" . $_REQUEST[ 'TotalResult' ] : '' ) . ( isset( $_REQUEST[ 'PageNo' ] ) ? "&PageNo=" . $_REQUEST[ 'PageNo' ] : '' );
    $filterarr = string_filter( stripos( $plist, "list.php?tid=" ) ? str_replace( $nofilter, '', $plist ) : $GLOBALS[ 'cfg_cmsurl' ] . "/plus/list.php?tid=" . $tid );
  }
  $cInfos = $dsql->GetOne( " Select * From  `#@__channeltype` where id='$channelid' " );
  $fieldset = $cInfos[ 'fieldset' ];
  $dtp = new DedeTagParse();
  $dtp->SetNameSpace( 'field', '<', '>' );
  $dtp->LoadSource( $fieldset );
  $result = '';
  if ( is_array( $dtp->CTags ) ) {
    foreach ( $dtp->CTags as $tida => $ctag ) {
      $field_name = $ctag->GetName();
      $fieldsname = $fieldsnamef ? explode( ",", $fieldsnamef ) : explode( ",", $field_name );
      if ( in_array( $field_name, $fieldsname ) ) {
        if ( $cfg_rewritea == 'Y' ) {
          $href = "";
          $addonfields_items = explode( ",", $ctag->GetAtt( 'default' ) );
          $i = array_search( $fieldrow[ $fieldsnamef ], explode( ",", $ctag->GetAtt( 'default' ) ) );
          $filterarr1 = explode( "list_", $filterarr );
          $href = $filterarr1[ 0 ] . "list_" . $tid . '_' . $field_name . '_' . $i;
          $href .= ".html";
          $href = str_replace( array( "_" . $field_name . ".", ".", "_" . $_REQUEST[ 'TotalResult' ] . "_" . $_REQUEST[ 'PageNo' ] ), array( ".", ".", "" ), $href );
          $result .= '<a href="' . $href . '">' . $addonfields_items[ $i ] . '</a>';
        } else {
          $addonfields_items = explode( ",", $ctag->GetAtt( 'default' ) );
          $i = array_search( $fieldrow[ $fieldsnamef ], explode( ",", $ctag->GetAtt( 'default' ) ) );
          $href = stripos( $filterarr, $ctag->GetName() . '=' ) ? str_replace( "=" . $fields_value, "=" . urlencode( $addonfields_items[ $i ] ), $filterarr ) : $filterarr . '&' . $ctag->GetName() . '=' . urlencode( $addonfields_items[ $i ] );
          $href = str_replace( "&TotalResult=" . $_REQUEST[ 'TotalResult' ] . "&PageNo=" . $_REQUEST[ 'PageNo' ], "", $href );
          $result .= '<a title="' . $addonfields_items[ $i ] . '" href="' . $href . '">' . $addonfields_items[ $i ] . '</a>';
        }
      }
    }
  }
  return $result;
}
/**
 *  内容页输出所属筛选值+无链接
 *  模板调用：{dede:field.id function=GetFilterTitle(@me,'bj')/}
 * @access    public
 * @param     string  $id文档id
 * @param     string  $fieldsnamef单个筛选字段
 * @return    string
 */
function GetFilterTitle( $id, $fieldsnamef ) {
  global $dsql, $cfg_cmspath, $cfg_rewritea;
  if ( !isset( $id ) && !is_numeric( $id ) ) {
    return '';
  } else {
    $arcrow = $dsql->GetOne( " Select typeid,channel From `#@__archives` where id='$id' " );
    $channelid = $arcrow[ 'channel' ];
    $tid = $arcrow[ 'typeid' ];
    $typerow = $dsql->GetOne( " Select typedir From `#@__arctype` where id='$tid' " );
    $typedir = MfTypedir( $typerow[ "typedir" ] );
    $channelrow = $dsql->GetOne( "SELECT addtable FROM #@__channeltype where id='$channelid'" );
    $addtable = trim( $channelrow[ 'addtable' ] );
    $fieldrow = $dsql->GetOne( "SELECT $fieldsnamef FROM `$addtable` WHERE aid=$id" );
  }
  $plist = $_SERVER[ 'HTTP_X_REWRITE_URL' ] ? string_filter( $_SERVER[ 'HTTP_X_REWRITE_URL' ] ) : string_filter( $_SERVER[ 'REQUEST_URI' ] );

  if ( $cfg_rewritea == 'Y' ) {
    $plist = stripos( $plist, "makehtml_list_action.php" ) ? $cfg_cmspath . $typedir . '/': $plist; //by巅峰
    $filterarr = string_filter( stripos( $plist, ".html" ) ? str_replace( ".html", "", $plist ) : $cfg_cmspath . $typedir . '/' );
  } else {
    $nofilter = ( isset( $_REQUEST[ 'TotalResult' ] ) ? "&TotalResult=" . $_REQUEST[ 'TotalResult' ] : '' ) . ( isset( $_REQUEST[ 'PageNo' ] ) ? "&PageNo=" . $_REQUEST[ 'PageNo' ] : '' );
    $filterarr = string_filter( stripos( $plist, "list.php?tid=" ) ? str_replace( $nofilter, '', $plist ) : $GLOBALS[ 'cfg_cmsurl' ] . "/plus/list.php?tid=" . $tid );
  }
  $cInfos = $dsql->GetOne( " Select * From  `#@__channeltype` where id='$channelid' " );
  $fieldset = $cInfos[ 'fieldset' ];
  $dtp = new DedeTagParse();
  $dtp->SetNameSpace( 'field', '<', '>' );
  $dtp->LoadSource( $fieldset );
  $result = '';
  if ( is_array( $dtp->CTags ) ) {
    foreach ( $dtp->CTags as $tida => $ctag ) {
      $field_name = $ctag->GetName();
      $fieldsname = $fieldsnamef ? explode( ",", $fieldsnamef ) : explode( ",", $field_name );
      if ( in_array( $field_name, $fieldsname ) ) {
        if ( $cfg_rewritea == 'Y' ) {
          $href = "";
          $addonfields_items = explode( ",", $ctag->GetAtt( 'default' ) );
          $i = array_search( $fieldrow[ $fieldsnamef ], explode( ",", $ctag->GetAtt( 'default' ) ) );
          $filterarr1 = explode( "list_", $filterarr );
          $href = $filterarr1[ 0 ] . "list_" . $tid . '_' . $field_name . '_' . $i;
          $href .= ".html";
          $href = str_replace( array( "_" . $field_name . ".", ".", "_" . $_REQUEST[ 'TotalResult' ] . "_" . $_REQUEST[ 'PageNo' ] ), array( ".", ".", "" ), $href );
          //$result .= '<a href="'.$href.'">'.$addonfields_items[$i].'</a>';
          $result .= $addonfields_items[ $i ];
        } else {
          $addonfields_items = explode( ",", $ctag->GetAtt( 'default' ) );
          $i = array_search( $fieldrow[ $fieldsnamef ], explode( ",", $ctag->GetAtt( 'default' ) ) );
          $href = stripos( $filterarr, $ctag->GetName() . '=' ) ? str_replace( "=" . $fields_value, "=" . urlencode( $addonfields_items[ $i ] ), $filterarr ) : $filterarr . '&' . $ctag->GetName() . '=' . urlencode( $addonfields_items[ $i ] );
          $href = str_replace( "&TotalResult=" . $_REQUEST[ 'TotalResult' ] . "&PageNo=" . $_REQUEST[ 'PageNo' ], "", $href );
          //$result .= '<a title="'.$addonfields_items[$i].'" href="'.$href.'">'.$addonfields_items[$i].'</a>';
          $result .= $addonfields_items[ $i ];
        }
      }
    }
  }
  return $result;
}
/*dede筛选自定义函数 结束*/

//获取顶级栏目名称
function GetTopTypename($id)
{
    global $dsql;
    $row = $dsql->GetOne("SELECT typename,topid FROM `#@__arctype` WHERE id= $id");
    if ($row['topid'] == '0')
    {
        return $row['typename'];
    }
    else
    {
        $row1 = $dsql->GetOne("SELECT typename FROM `#@__arctype` WHERE id= $row[topid]");
        return $row1['typename'];
    }
}
